﻿using System;
using System.Windows.Forms;

namespace sy1_1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        // 文本框回车事件：输入姓名后按回车显示结果
        private void txtName_KeyPress(object sender, KeyPressEventArgs e)
        {
            // 判断是否按下回车键
            if (e.KeyChar == (char)Keys.Enter)
            {
                // 将输入的姓名显示到结果标签
                lblResult.Text = txtName.Text;
                // 吸收回车键，避免窗体响应
                e.Handled = true;
            }
        }
    }
}
